﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LinkyPOS.Class;

namespace LinkyPOS
{
    public partial class Raftakiler : Form
    {
        public Raftakiler()
        {
            InitializeComponent();
        }
         linkDataContext ly = new linkDataContext();
        siparisler2 s = new siparisler2();
        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {

         
        }

        private void button1_Click(object sender, EventArgs e)
        {
          

                List<siparisler2> raft = s.raftakiler();
                foreach (var item in raft)
	{ ListViewItem lst= new ListViewItem();
                        lst.Text = item.Sipariskodu.ToString();
                       
                        lst.SubItems.Add(item.Net.ToString());
                        switch (item.Durum)
                        {
                            case 2:
                                lst.SubItems.Add("Nakit-Rafta");
                                break;
                            case 3:
                                lst.SubItems.Add("Kredi Kartı-Rafta");
                                break;
                       
                            default:
                                lst.SubItems.Add("Cari-Rafta");
                                break;
                        }
                        lst.SubItems.Add(item.Alimtarihi.ToString());
                        lst.SubItems.Add(item.Odemetarihi.ToString());
                        lst.SubItems.Add(item.musteribilgileri.ToString());

                        lstSiparisler.Items.Add(lst);
                }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
            xla.Visible = true;
            Microsoft.Office.Interop.Excel.Workbook wb = xla.Workbooks.Add(Microsoft.Office.Interop.Excel.XlSheetType.xlWorksheet);
            Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)xla.ActiveSheet;
            ws.StandardWidth = 30;
            
            
     
            int i = 2;
            int j = 1;

            ws.Cells[1,1] = "Sipariş Kodu";
            
            ws.Cells[1, 2] = "Siparis Net Tutarı";
            ws.Cells[1, 3] = "Ödeme Tipi";
            ws.Cells[1, 4] = "Kayit Tarihi";
            ws.Cells[1, 5] = "Ödeme Tarihi";
            ws.Cells[1, 6] = "Müşteri Bilgileri";
            foreach (ListViewItem item in lstSiparisler.Items)
            {
                ws.Cells[i, j] = item.Text.ToString();
                foreach (ListViewItem.ListViewSubItem subitem in item.SubItems)
                {
                    ws.Cells[i, j] = subitem.Text.ToString();
                    j++;
                }
                j = 1;
                i++;
            }





        }

        private void Raftakiler_Load(object sender, EventArgs e)
        {
            this.Location = new Point(0, 0);
            this.Size = Screen.PrimaryScreen.WorkingArea.Size;


            List<siparisler2> raft = s.raftakiler();
            foreach (var item in raft)
            {
                ListViewItem lst = new ListViewItem();
                lst.Text = item.Sipariskodu.ToString();

                lst.SubItems.Add(item.Net.ToString());
                switch (item.Durum)
                {
                    case 2:
                        lst.SubItems.Add("Nakit-Rafta");
                        break;
                    case 3:
                        lst.SubItems.Add("Kredi Kartı-Rafta");
                        break;

                    default:
                        lst.SubItems.Add("Cari-Rafta");
                        break;
                }
                lst.SubItems.Add(item.Alimtarihi.ToString());
                lst.SubItems.Add(item.Odemetarihi.ToString());
                lst.SubItems.Add(item.musteribilgileri.ToString());

                lstSiparisler.Items.Add(lst);
            }

        }
    }
}
